/*
 * Project CHEN Rendering Engine : /scereader.cpp
 * Created: 2021-02-02, Last modified:  2021-02-02
 * 
 * This is an control console over the entire program.
 * This module can also serve as a convenient scene script
 * parser for scene construction.
 * 
 * Copyright (C) 2021 Hineven (hineven@pku.edu.cn)
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "control.hpp"

namespace chen {
// 符号表
static std::map<std::string, void*> symtab;

static std::pair<std::string, std::string> subsplit (std::string str, char div = '.') {

    int p = str.find_first_of(div);
    if(p == std::string::npos) return std::make_pair(str, (std::string)"");
    std::string s1 = str.substr(0, p);
    std::string s2 = str.substr(p+1, str.length()-p-1);
    return std::make_pair(s1, s2);
}

static std::string strip (std::string str) {
    int i = 0, j;
    for(; i<str.length() &&
        (str[i] == ' ' || str[i] == '\n' || str[i] == '\t' || str[i] == '\r');
        i++);
    for(j = i; j<str.length() &&
        (str[j] != ' ' && str[j] != '\n' && str[j] != '\t' && str[j] != '\r');
        j++) ;
    return str.substr(i, j-i+1);
}

bool executeCommand (std::string cmd) {
    auto sub = subsplit(cmd, ' ');
    if(sub.second == "") {
        cmd = strip(sub.first);
        if(cmd == "render") {
            ((Shader*)symtab["shader"])->render();
        }
    } else {
        
    }
}

void consoleMain () {
    while(true) {

    }
}
}
